package com.eml.service.service.impl;


import com.eml.service.dao.UserDao;
import com.eml.service.dao.impl.UserDaoImpl;
import com.eml.service.entity.Merchant;
import com.eml.service.entity.User;
import com.eml.service.service.UserService;

public class UserServiceImpl implements UserService {
    /**
     * 用户登录
     * */
    private UserDao userDao = new UserDaoImpl();
    @Override
    public User userLogin(String userName, String userPassword) throws Exception {
        User user = userDao.userLogin(userName);
        if (user == null){
            throw new Exception("用户不存在");
        } else if (!userPassword.equals(user.getUserPassword())) {
            throw new Exception("密码错误");
        }
        return user;
    }
    /**
     * 用户注册
     * */
    @Override
    public void userRegister(User user) throws Exception {
        userDao.userRegister(user);
    }
    /**
     * 修改密码
     * */
    @Override
    public void updateUserPassword(String userName,String userPassword) throws Exception {
        int i = userDao.updateUserPassword(userName, userPassword);
        if (i == 0){
            throw new Exception("修改失败，用户不存在");
        }
    }
    /**
     *查询个人信息
     **/
    @Override
    public User selectUserInfo(String username, String userPassword) throws Exception {
        User user = userDao.selectUserInfo(username, userPassword);
        if (user == null){
            throw new Exception("用户不存在");
        } else if (!userPassword.equals(user.getUserPassword())) {
            throw new Exception("密码错误");
        }
        return user;
    }

    @Override
    public Merchant selectMerchantInfo(String merchantName) throws Exception {
        Merchant merchant = userDao.selectMerchantInfo(merchantName);
        if (merchant != null){
            return merchant;
        }
        throw new Exception("商家不存在");
    }

    @Override
    public void selectMenuInfo() throws Exception {

    }

    @Override
    public void commitOrderStatus() throws Exception {

    }

    @Override
    public void selectOrderStatus() throws Exception {

    }

    @Override
    public void selectPayment() throws Exception {

    }

    @Override
    public void selectDelivererStatus() throws Exception {

    }

    @Override
    public void updateOrderStatus() throws Exception {

    }

    @Override
    public void commitReview() throws Exception {

    }

    @Override
    public void commitFeedback() throws Exception {

    }
}
